package WinterVacation.Day10;

public class LeetCode27 {
    public static int removeElement(int[] nums, int val) {
        if(nums.length == 0){
            return 0;
        }
        int size = nums.length;
        for (int i = 0; i < size; i++) {
            if(i == size - 1 && nums[i] == val){
                size--;
                break;
            }
            if(nums[i] == val){
                for (int j = i; j + 1< size; j++) {
                    nums[j] = nums[j + 1];
                }
                i--;
                size--;
            }
        }
        return size;
    }

    public static void main(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};
        System.out.println(removeElement(arr,2));
    }
}
